package com.pms.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pms.common.annotation.Log;
import com.pms.common.core.controller.BaseController;
import com.pms.common.core.domain.AjaxResult;
import com.pms.common.enums.BusinessType;
import com.pms.system.domain.PmsClientInfo;
import com.pms.system.service.IPmsClientInfoService;
import com.pms.common.utils.poi.ExcelUtil;
import com.pms.common.core.page.TableDataInfo;

/**
 * 客户信息Controller
 * 
 * @author 达瓦里氏
 * @date 2023-03-04
 */
@RestController
@RequestMapping("/system/PmsClientInfo")
public class PmsClientInfoController extends BaseController
{
    @Autowired
    private IPmsClientInfoService pmsClientInfoService;

    /**
     * 查询客户信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsClientInfo pmsClientInfo)
    {
        startPage();
        List<PmsClientInfo> list = pmsClientInfoService.selectPmsClientInfoList(pmsClientInfo);
        return getDataTable(list);
    }

    /**
     * 查询客户信息列表List
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:ClientList')")
    @GetMapping("/ClientList")
    public List<PmsClientInfo>  ClientList(PmsClientInfo pmsClientInfo)
    {
        List<PmsClientInfo> list = pmsClientInfoService.selectPmsClientInfoList(pmsClientInfo);
        return list;
    }

    /**
     * 导出客户信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:export')")
//    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsClientInfo pmsClientInfo)
    {
        List<PmsClientInfo> list = pmsClientInfoService.selectPmsClientInfoList(pmsClientInfo);
        ExcelUtil<PmsClientInfo> util = new ExcelUtil<PmsClientInfo>(PmsClientInfo.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsClientInfoService.selectPmsClientInfoById(id));
    }


    /**
     * 获取客户信息详细信息
     */
    @GetMapping(value = "/getInfoByCode/{code}")
    public AjaxResult getInfoByCode(@PathVariable("code") String code)
    {   PmsClientInfo pmsClientInfo = pmsClientInfoService.selectPmsClientInfoByCode(code);
        if (pmsClientInfo != null){
            return success(pmsClientInfo);
        }else{
            return error("暂未查询到客户信息");
        }
    }

    /**
     * 新增客户信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:add')")
//    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsClientInfo pmsClientInfo)
    {
        return toAjax(pmsClientInfoService.insertPmsClientInfo(pmsClientInfo));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:edit')")
//    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsClientInfo pmsClientInfo)
    {
        return toAjax(pmsClientInfoService.updatePmsClientInfo(pmsClientInfo));
    }

    /**
     * 删除客户信息
     */
//    @PreAuthorize("@ss.hasPermi('system:PmsClientInfo:remove')")
//    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsClientInfoService.deletePmsClientInfoByIds(ids));
    }
}
